package com.xupla.helloworld;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {
	public final static String EXTRA_MESSAGE = "com.xupla.helloworld.MESSAGE";
	
	
	
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //  let user know the app is running.
        try {
			beep();
		} catch (Exception e) {		
			e.printStackTrace();
		}
        // Fragment Lesson
        XuplaFragment frag = new XuplaFragment( R.layout.activity_display_message );

        getFragmentManager().beginTransaction().add(R.id.layout_container, frag).commit();        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    public void button_error_test_onClick( View view ) throws Exception
    {
    	XuplaErrorHandler eh = new XuplaErrorHandler( true, this );
    	eh.handleError( "test", this );
    	
    }
    
    public void sendMessage( View view ) throws Exception
    {
    	XuplaFragment newF = new XuplaFragment( R.layout.activity_fullscreen_error );
    	getFragmentManager().beginTransaction().replace(R.id.layout_container, newF ).commit();
    	
    	
    	/*XuplaErrorHandler eh = new XuplaErrorHandler( true, this );
    	eh.handleError( "test", this );*/
    	
    	/*// Create next activity ( from tutorial )
    	Intent intent = new Intent(this, DisplayMessageActivity.class);
    	EditText edtTxt = (EditText) findViewById( R.id.edit_message);
    	String message = edtTxt.getText().toString();
    	
    	intent.putExtra(EXTRA_MESSAGE, message);
    	startActivity(intent);    	       */
    }
    
    private void toggleNoise( View view ) throws Exception
    {
    	
    	
    }
    
    private void beep() throws Exception
    {
	   try {
	 	    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
	        Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
	        r.play();    
        
    } catch (Exception e) {
      	XuplaErrorHandler eh = new XuplaErrorHandler( true, this );
    	eh.handleError( e.getMessage(), this );
    }                       
	 
   }
}
